package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

class zbx {
   private Workbook a;
   private WorksheetCollection b;
   private zbwd c;
   private int d;
   private static final com.aspose.cells.b.c.a.za e = new com.aspose.cells.b.c.a.za(new String[]{"Normal", "Comma", "Currency", "Percent", "Comma [0]", "Currency [0]"});

   public zbx(Workbook var1, zbwd var2) {
      this.a = var1;
      this.b = var1.getWorksheets();
      this.d = this.b.getCount();
      this.c = var2;
   }

   void a(zqa var1, int[] var2) throws Exception {
      zca var3 = new zca(this.b.l());
      var3.a(var1);
      if (this.c.d != null && this.c.d.a) {
         var1.a((int)96);
      }

      if (this.a.getSettings().isWriteProtected()) {
         var1.a((int)134);
      }

      zvf var4;
      byte[] var5;
      zsg var10;
      byte[] var20;
      if (this.a.getSettings().getPassword() != null && !"".equals(this.a.getSettings().getPassword())) {
         if (this.a.e() == 0) {
            var4 = new zvf();
            var4.a(this.a.getSettings().getPassword());
            var4.a((zqa)var1);
         } else if (this.a.e() == 1) {
            var20 = com.aspose.cells.b.a.zh.b().a();
            var5 = new byte[32];
            byte[] var6 = Encoding.getUnicode().a(this.a.getSettings().getPassword());
            System.arraycopy(var6, 0, var5, 0, var6.length);
            zamp var7 = new zamp();
            byte[] var8 = new byte[16];
            byte[] var9 = new byte[16];
            var7.a(var5, var20);
            var7.a(var20, var8, var9);
            var10 = new zsg(this.a.getSettings().getPassword(), var20, var8, var9);
            this.c.f = var10;
            zvf var11 = new zvf();
            var11.a(var10);
            var11.a((zqa)var1);
         } else {
            zby var21 = zby.a(this.a.getSettings().getPassword(), this.a.e(), this.a.f());
            zvf var22 = new zvf();
            var22.a(var21);
            var22.a((zqa)var1);
            this.c.e = var21;
         }
      } else if (this.a.getWorksheets().P() && (this.a.getWorksheets().N().b() & '\uffff') != 0) {
         this.c.f = zsg.a();
         var4 = new zvf();
         var4.a(this.c.f);
         var4.a((zqa)var1);
      }

      if (this.a.getSettings().isWriteProtected()) {
         zvg var23 = new zvg(this.a);
         var23.a(var1);
      }

      if (this.b.y() != null && this.b.y().a() != null && this.b.y().a().size() != 0) {
         for(int var24 = 0; var24 < this.b.y().a().size(); ++var24) {
            var5 = (byte[])((byte[])this.b.y().a().get(var24));
            var1.a(var5);
         }
      }

      var20 = new byte[]{66, 0, 2, 0, -80, 4};
      System.arraycopy(com.aspose.cells.b.a.zc.a(this.a.getSettings().b), 0, var20, 4, 2);
      var1.a(var20);
      if (this.b.i() || this.b.l != null) {
         var1.a((int)211);
         if (this.b.j()) {
            var1.a((int)445);
         }
      }

      if (this.b.h() != null) {
         zkb var25 = new zkb();
         var25.a(this.b.h());
         var25.a(var1);
      }

      if (this.d < 4113) {
         var1.c(317);
         var1.c(2 * this.d);

         for(int var26 = 0; var26 < this.d; ++var26) {
            var1.c(this.b.get(var26).l());
         }
      }

      if (this.b.getOleSize() != null) {
         zasc var29 = new zasc((CellArea)this.b.getOleSize());
         var29.a(var1);
      }

      if (this.b.P()) {
         zbvh var30 = this.b.i;
         var1.c(25);
         var1.c(2);
         if (var30.a) {
            var1.c(1);
         } else {
            var1.c(0);
         }

         var1.c(18);
         var1.c(2);
         if (var30.b) {
            var1.c(1);
         } else {
            var1.c(0);
         }

         var1.c(19);
         int var27 = var30.b();
         if ((var27 & '\uffff') == 0) {
            var1.c(2);
            var1.c(0);
         } else {
            var1.c(2);
            var1.b(var27);
         }
      }

      if (this.b.y() != null) {
         this.b.y().a(var1);
      }

      this.c(var1);
      zxr var32 = new zxr();
      HashMap var28 = new HashMap();

      for(int var31 = 0; var31 < this.b.z().size(); ++var31) {
         Font var34 = (Font)this.b.z().get(var31);
         zbvr var36 = var32.a(var34, 5);
         if (var36 != null && var36.getCount() != 0) {
            var28.put(var31 >= 4 ? var31 + 1 : var31, var36);
         }

         var32.a(var1);
      }

      for(int var35 = 0; var35 < this.b.A().size(); ++var35) {
         zxw var33 = (zxw)this.b.A().get(var35);
         var33.a(var1);
      }

      zbvs var37 = new zbvs();
      HashMap var38 = new HashMap();
      com.aspose.cells.a.e.zh var39 = new com.aspose.cells.a.e.zh();
      Style var12;
      int var40;
      if (this.c != null && this.c.b != null) {
         for(var40 = 0; var40 < this.c.b.e; ++var40) {
            var12 = this.b.B().a(var40);
            this.a(var12, var40, var37, var39, var28, var38);
            var37.a(var1);
         }

         for(var40 = 0; var40 < this.c.b.h.size(); ++var40) {
            var12 = (Style)this.c.b.h.get(var40);
            this.a(var12, var40 + this.c.b.e, var37, var39, var28, var38);
            var37.a(var1);
         }
      } else {
         for(var40 = 0; var40 < this.b.B().getCount(); ++var40) {
            var12 = this.b.B().a(var40);
            this.a(var12, var40, var37, var39, var28, var38);
            var37.a(var1);
         }
      }

      int var41;
      if (var38.size() != 0) {
         zbvo var42 = new zbvo();
         var42.a(this.b.B().getCount(), (long)var39.a());
         var42.a(var1);

         for(var41 = 0; var41 < this.b.B().getCount(); ++var41) {
            zbvr var13 = (zbvr)var38.get(var41);
            if (var13 != null) {
               zbvq var14 = new zbvq();
               var14.a(var41, var13);
               var14.a(var1);
            }
         }
      }

      var10 = null;
      this.a(var1);

      for(var40 = 0; var40 < this.b.B().getCount(); ++var40) {
         var12 = this.b.B().a(var40);
         if (var12.getName() != null && !"".equals(var12.getName())) {
            zbqb var43 = new zbqb();
            switch(e.a(var12.getName())) {
            case 0:
               var43.a(var40, (byte)0);
               break;
            case 1:
               var43.a(var40, (byte)3);
               break;
            case 2:
               var43.a(var40, (byte)4);
               break;
            case 3:
               var43.a(var40, (byte)5);
               break;
            case 4:
               var43.a(var40, (byte)6);
               break;
            case 5:
               var43.a(var40, (byte)7);
               break;
            default:
               var43.a(var40, var12.getName());
            }

            var43.a(var1);
         }
      }

      this.b(var1);
      zasv var46 = new zasv();
      var46.a(this.b.m());
      var46.a(var1);
      if (this.b.f != null) {
         for(var41 = 0; var41 < this.b.f.getCount(); ++var41) {
            zbuf var44 = new zbuf();
            var44.a(this.b.f.a(var41));
            var44.a(var1);
         }

         var1.c(352);
         var1.c(2);
         if (this.b.g()) {
            var1.c(1);
         } else {
            var1.c(0);
         }
      }

      if (this.b.V() != null && this.b.V().getCount() != 0) {
         Iterator var49 = this.b.V().iterator();

         while(var49.hasNext()) {
            zauk var45 = (zauk)var49.next();
            var45.a(var1);
         }
      }

      if (this.b.g()) {
         var1.c(352);
         var1.c(2);
         var1.c(1);
      }

      for(var41 = 0; var41 < this.d; ++var41) {
         var2[var41] = (int)(var1.b() + 4L);
         Worksheet var47 = this.b.get(var41);
         String var48 = var47.getName();
         short var15 = (short)(var47.o() & 255);
         if (var47.getType() == 0) {
            var15 = (short)(var15 + 1536);
         } else if (var47.getType() == 2) {
            var15 = (short)(var15 + 512);
         } else if (var47.getType() == 3) {
            var15 = (short)(var15 + 256);
         }

         zdc var16 = new zdc(var15, var48, 5);
         var16.a(var1);
      }

      zmr var53 = new zmr(this.a.getSettings().getLanguageCode(), this.a.getSettings().getRegion());
      var53.a(var1);
      byte var50 = -1;
      if (this.b.v() != null && this.b.v().getCount() != 0) {
         for(int var51 = 0; var51 < this.b.v().getCount(); ++var51) {
            zbqg var58 = this.b.v().a(var51);
            zbqh var56 = new zbqh();
            var56.a(var58, this.d);
            var56.a(var1);

            for(int var17 = 0; var17 < var58.b().size(); ++var17) {
               zul var18 = new zul();
               var18.a((zuk)var58.b().get(var17));
               var18.a(var1);
            }

            if (var58.d() != null) {
               ArrayList var61 = var58.d();

               for(int var63 = 0; var63 < var61.size(); ++var63) {
                  zut var19 = (zut)var61.get(var63);
                  if (var19 != null && var19.e()) {
                     this.a(var1, var19, var63);
                  }
               }
            }
         }
      }

      this.b(var1, var50);
      this.a(var1, var50);
      zayg var52 = new zayg(this.b.n().getSettings().f);
      var52.a(var1);
      if (this.b.T() != null && this.b.T().b().getCount() != 0) {
         zayt var54 = new zayt();
         var54.a(this.b, this.b.T());
         var54.b(var1);
      }

      if (this.b.R() != null) {
         zamq var55 = new zamq(this.b, 0);
         var55.a(this.b.R());
         var55.a(var1);
      }

      zbmc var57 = new zbmc();
      if (this.c != null && this.c.b != null) {
         var57.a(this.b.g, this.c.b);
      } else {
         var57.a(this.b.g);
      }

      var57.a(var1);
      if (this.a.getSettings().d != null) {
         var1.a(this.a.getSettings().d.a());
      }

      if (this.b.y() != null) {
         this.b.y().b(var1);
      }

      zbte var60;
      if (this.a.c.b()) {
         var60 = new zbte();
         var60.a(this.a);
         var60.a(var1);
      } else if (this.a.c.c == 124226) {
         var60 = new zbte(this.a.c.c);
         var60.a(var1);
      }

      zmd var62 = new zmd(0, this.b.n().getSettings().getCheckComptiliblity());
      var62.a(var1);
      zrx var59 = new zrx();
      var59.a(var1);
   }

   private void a(zqa var1) throws Exception {
      TableStyleCollection var2 = this.a.getWorksheets().Z();
      if (var2 != null && var2.getCount() != 0) {
         DxfCollection var3 = this.a.getWorksheets().getDxfs();
         int var4 = var3.getCount();
         if (var4 != 0) {
            for(int var5 = 0; var5 < var3.getCount(); ++var5) {
               Style var6 = var3.get(var5);
               zrv var7 = new zrv();
               var7.a(var6, false, this.a);
               var7.a(var1);
            }

         }
      }
   }

   private void b(zqa var1) throws Exception {
      TableStyleCollection var2 = this.a.getWorksheets().Z();
      if (var2 != null) {
         int var3 = var2.getCount();
         if (var3 != 0) {
            zbsl var4 = new zbsl(var2);
            var4.a(var1);

            for(int var5 = 0; var5 < var3; ++var5) {
               TableStyle var6 = var2.get(var5);
               this.a(var6, var1);
            }

         }
      }
   }

   private void a(TableStyle var1, zqa var2) throws Exception {
      zbsk var3 = new zbsk(var1);
      var3.a(var2);
      int var4 = var1.getTableStyleElements().getCount();

      for(int var5 = 0; var5 < var4; ++var5) {
         TableStyleElement var6 = var1.getTableStyleElements().get(var5);
         zbsi var7 = new zbsi(var6);
         var7.a(var2);
      }

   }

   private void c(zqa var1) throws Exception {
      WorkbookSettings var2 = this.a.getSettings();
      if (this.b.getActiveSheetIndex() - this.b.C() > 10) {
         this.b.l(this.b.getActiveSheetIndex() - 10);
      }

      zbvf var3 = new zbvf(this.b);
      var3.a(var1);
      var1.c(64);
      var1.c(2);
      var1.c(0);
      var1.c(141);
      var1.c(2);
      switch(var2.getDisplayDrawingObjects()) {
      case 0:
         var1.c(0);
         break;
      case 1:
         var1.c(1);
         break;
      case 2:
         var1.c(2);
         break;
      default:
         var1.c(0);
      }

      var1.c(34);
      var1.c(2);
      if (var2.getDate1904()) {
         var1.c(1);
      } else {
         var1.c(0);
      }

      var1.c(14);
      var1.c(2);
      if (var2.getPrecisionAsDisplayed()) {
         var1.c(0);
      } else {
         var1.c(1);
      }

      var1.c(439);
      var1.c(2);
      var1.c(0);
      var1.c(218);
      var1.c(2);
      var1.a(var2.j());
   }

   private void a(zqa var1, zut var2, int var3) throws Exception {
      byte[] var4 = new byte[8];
      var4[0] = 89;
      var4[2] = 4;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var2.a.size()), 0, var4, 4, 2);
      System.arraycopy(com.aspose.cells.b.a.zc.a(var3), 0, var4, 6, 2);
      var1.a(var4);

      for(int var5 = 0; var5 < var2.a.size(); ++var5) {
         zuq var6 = (zuq)var2.a.get(var5);
         if (var6.d()) {
            zef var7 = new zef();
            var7.a(var6);
            var7.a(var1);
         }
      }

   }

   private void a(zqa var1, int var2) throws Exception {
      NameCollection var3 = this.b.getNames();

      for(int var4 = 0; var4 < var3.getCount(); ++var4) {
         Name var5 = var3.get(var4);
         zaof var6 = new zaof(var5);
         var6.a(var1);
         if (var5.getComment() != null && !"".equals(var5.getComment())) {
            zaod var7 = new zaod();
            var7.a(var5);
            var7.a(var1);
         }
      }

   }

   private void b(zqa var1, int var2) throws Exception {
      zbqf var3 = this.b.v();
      if (var3 != null && var3.getCount() != 0) {
         for(int var4 = 0; var4 < var3.getCount(); ++var4) {
            zbqg var5 = var3.a(var4);
            if (var5.e()) {
               break;
            }
         }
      }

      zuu var6 = new zuu(this.b.l());
      this.b.q().a(var6.a);
      var6.a(var1);
   }

   private void a(Style var1, int var2, zbvs var3, com.aspose.cells.a.e.zh var4, HashMap var5, HashMap var6) {
      var3.a();
      var3.a(var1.getFont().j());
      zbvr var7 = var3.a(var1, var2);
      var4.a(var3.e());
      zbvr var8 = (zbvr)var5.get(var1.getFont().j());
      if (var8 != null) {
         var7.a(var8);
      }

      if (var7.getCount() != 0) {
         var6.put(var2, var7);
      }

   }
}
